import { GameObjects, Scene } from "phaser";

export class Boom extends GameObjects.Sprite {
    constructor(scene: Scene, x: number, y: number, texture: string) {
        // 创建对象
        super(scene, x, y, texture);

        // 爆炸动画播放结束事件
        this.on("animationcomplete-boom", this.hide, this);
    }
    /**
     * 显示爆炸
     * @param x 爆炸x坐标
     * @param y 爆炸y坐标
     */
    show(x: number, y: number) {
        this.x = x;
        this.y = y;
        this.setActive(true);
        this.setVisible(true);
        // 爆炸动画
        this.play("boom");
        // 爆炸音效
        this.scene.sound.play("boom");
    }
    /**
     * 隐藏爆炸
     */
    hide() {
        this.setActive(false);
        this.setVisible(false);
    }
}
